/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ServiceSettingsFrame.java
 *
 * Created on Aug 11, 2010, 5:50:25 AM
 */

package nsdh.view;

import nsdh.*;
import javax.swing.table.*;
import javax.swing.*;
import java.util.*;
import nsdh.model.script_models.*;

/**
 *
 * @author notroot
 */
public class ServiceSettingsFrame extends javax.swing.JFrame {

    /** Creates new form ServiceSettingsFrame */
    public ServiceSettingsFrame(NsdhController nsdhController, GraphPanel graphPanel, NetworkSettingsFrame networkSettingsFrame, String serviceName) {
        initComponents();
        this.nsdhController = nsdhController;
        this.graphPanel = graphPanel;
        this.serviceName = serviceName;
        this.networkSettingsFrame = networkSettingsFrame;

        loadServiceFromNsdhModel();

        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        serviceNameLabel = new javax.swing.JLabel();
        serviceNameTextField = new javax.swing.JTextField();
        clientPanel = new javax.swing.JPanel();
        clientAgentTypeLabel = new javax.swing.JLabel();
        clientParamsLabel = new javax.swing.JLabel();
        clientParamsScrollPane = new javax.swing.JScrollPane();
        clientParamsTable = new javax.swing.JTable();
        clientAgentTypeComboBox = new javax.swing.JComboBox();
        serverPanel = new javax.swing.JPanel();
        serverTransportPanel = new javax.swing.JPanel();
        serverTransportAgentTypeLabel = new javax.swing.JLabel();
        serverTransportAgentTypeComboBox = new javax.swing.JComboBox();
        serverTransportParamsScrollPane = new javax.swing.JScrollPane();
        serverTransportParamsTable = new javax.swing.JTable();
        serverTransportParamsLabel = new javax.swing.JLabel();
        serverApplicationPanel = new javax.swing.JPanel();
        serverApplicationAgentTypeLabel = new javax.swing.JLabel();
        serverApplicationAgentTypeComboBox = new javax.swing.JComboBox();
        serverApplicationParamsScrollPane = new javax.swing.JScrollPane();
        serverApplicationParamsTable = new javax.swing.JTable();
        serverApplicationParamsLabel = new javax.swing.JLabel();
        okButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Parametry uslugi");
        setBounds(new java.awt.Rectangle(0, 0, 0, 0));

        serviceNameLabel.setText("Nazwa uslugi:");

        clientPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Klient"));

        clientAgentTypeLabel.setText("Typ:");

        clientParamsLabel.setText("Parametry:");

        clientParamsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        clientParamsScrollPane.setViewportView(clientParamsTable);

        clientAgentTypeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Agent/TCPSink", "Agent/TCPSink/DelAck", "Agent/TCPSink/Sack1", "Agent/TCPSink/Sack1/DelAck", "Agent/Null" }));
        clientAgentTypeComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clientAgentTypeComboBoxActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout clientPanelLayout = new javax.swing.GroupLayout(clientPanel);
        clientPanel.setLayout(clientPanelLayout);
        clientPanelLayout.setHorizontalGroup(
            clientPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, clientPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(clientPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(clientPanelLayout.createSequentialGroup()
                        .addComponent(clientAgentTypeLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(clientAgentTypeComboBox, 0, 0, Short.MAX_VALUE))
                    .addComponent(clientParamsLabel)
                    .addComponent(clientParamsScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 277, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(83, 83, 83))
        );
        clientPanelLayout.setVerticalGroup(
            clientPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(clientPanelLayout.createSequentialGroup()
                .addGroup(clientPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(clientAgentTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(clientAgentTypeLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(clientParamsLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(clientParamsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 456, Short.MAX_VALUE)
                .addContainerGap())
        );

        serverPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Serwer"));

        serverTransportPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Warstwa Transportu"));

        serverTransportAgentTypeLabel.setText("Typ:");

        serverTransportAgentTypeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Agent/TCP", "Agent/TCP/Reno", "Agent/TCP/NewReno", "Agent/TCP/Sack1", "Agent/TCP/Vegas", "Agent/TCP/Fack", "Agent/TCP/Linux", "Agent/UDP" }));
        serverTransportAgentTypeComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                serverTransportAgentTypeComboBoxActionPerformed(evt);
            }
        });

        serverTransportParamsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        serverTransportParamsScrollPane.setViewportView(serverTransportParamsTable);

        serverTransportParamsLabel.setText("Parametry:");

        javax.swing.GroupLayout serverTransportPanelLayout = new javax.swing.GroupLayout(serverTransportPanel);
        serverTransportPanel.setLayout(serverTransportPanelLayout);
        serverTransportPanelLayout.setHorizontalGroup(
            serverTransportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(serverTransportPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(serverTransportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(serverTransportParamsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)
                    .addGroup(serverTransportPanelLayout.createSequentialGroup()
                        .addComponent(serverTransportAgentTypeLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(serverTransportAgentTypeComboBox, 0, 263, Short.MAX_VALUE))
                    .addComponent(serverTransportParamsLabel))
                .addContainerGap())
        );
        serverTransportPanelLayout.setVerticalGroup(
            serverTransportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(serverTransportPanelLayout.createSequentialGroup()
                .addGroup(serverTransportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(serverTransportAgentTypeLabel)
                    .addComponent(serverTransportAgentTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(serverTransportParamsLabel)
                .addGap(12, 12, 12)
                .addComponent(serverTransportParamsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 409, Short.MAX_VALUE)
                .addContainerGap())
        );

        serverApplicationPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Warstwa Aplikacji"));

        serverApplicationAgentTypeLabel.setText("Typ:");

        serverApplicationAgentTypeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Application/Traffic/Exponential", "Application/Traffic/Pareto", "Application/Traffic/CBR", "Application/Telnet", "Application/FTP" }));
        serverApplicationAgentTypeComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                serverApplicationAgentTypeComboBoxActionPerformed(evt);
            }
        });

        serverApplicationParamsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        serverApplicationParamsScrollPane.setViewportView(serverApplicationParamsTable);

        serverApplicationParamsLabel.setText("Parametry:");

        javax.swing.GroupLayout serverApplicationPanelLayout = new javax.swing.GroupLayout(serverApplicationPanel);
        serverApplicationPanel.setLayout(serverApplicationPanelLayout);
        serverApplicationPanelLayout.setHorizontalGroup(
            serverApplicationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(serverApplicationPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(serverApplicationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(serverApplicationParamsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)
                    .addGroup(serverApplicationPanelLayout.createSequentialGroup()
                        .addComponent(serverApplicationAgentTypeLabel)
                        .addGap(18, 18, 18)
                        .addComponent(serverApplicationAgentTypeComboBox, 0, 223, Short.MAX_VALUE))
                    .addComponent(serverApplicationParamsLabel))
                .addContainerGap())
        );
        serverApplicationPanelLayout.setVerticalGroup(
            serverApplicationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(serverApplicationPanelLayout.createSequentialGroup()
                .addGroup(serverApplicationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(serverApplicationAgentTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(serverApplicationAgentTypeLabel))
                .addGap(12, 12, 12)
                .addComponent(serverApplicationParamsLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(serverApplicationParamsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 409, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout serverPanelLayout = new javax.swing.GroupLayout(serverPanel);
        serverPanel.setLayout(serverPanelLayout);
        serverPanelLayout.setHorizontalGroup(
            serverPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(serverPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(serverTransportPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(serverApplicationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        serverPanelLayout.setVerticalGroup(
            serverPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, serverPanelLayout.createSequentialGroup()
                .addGroup(serverPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(serverTransportPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(serverApplicationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        okButton.setText("OK");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        cancelButton.setText("Anuluj");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(serviceNameLabel)
                                .addGap(18, 18, 18)
                                .addComponent(serviceNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(serverPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(clientPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 311, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(423, 423, 423))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(serviceNameLabel)
                    .addComponent(serviceNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(clientPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(serverPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(okButton)
                    .addComponent(cancelButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        
        try{
            graphPanel.saveCellsToNsdhModel();
            saveServiceToNsdhModel();
            networkSettingsFrame.LoadServiceTableFromNsdhModel();
            graphPanel.loadEdgesFromNsdhModel();
            this.dispose();
        }catch(Exception e){
            JOptionPane.showMessageDialog(this, e.getMessage(), "Ostrzeżenie", JOptionPane.WARNING_MESSAGE);
        }

        
    }//GEN-LAST:event_okButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        this.dispose();
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void clientAgentTypeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clientAgentTypeComboBoxActionPerformed
        createClientParamsTableFields((String)clientAgentTypeComboBox.getSelectedItem());
    }//GEN-LAST:event_clientAgentTypeComboBoxActionPerformed

    private void serverTransportAgentTypeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_serverTransportAgentTypeComboBoxActionPerformed
        createServerTransportParamsTableFields((String)serverTransportAgentTypeComboBox.getSelectedItem());
    }//GEN-LAST:event_serverTransportAgentTypeComboBoxActionPerformed

    private void serverApplicationAgentTypeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_serverApplicationAgentTypeComboBoxActionPerformed
        createServerApplicationParamsTableFields((String)serverApplicationAgentTypeComboBox.getSelectedItem());
    }//GEN-LAST:event_serverApplicationAgentTypeComboBoxActionPerformed

    private void loadServiceFromNsdhModel(){

        //pobierz nazwe uslugi
        if(serviceName!=null && !serviceName.equals("")){
            serviceNameTextField.setText(serviceName);

            clientAgentTypeComboBox.setSelectedItem(nsdhController.nsdhModel.network_settings.service_list.get(serviceName).client_sink.client_agent);
            serverTransportAgentTypeComboBox.setSelectedItem(nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_transport.server_agent);
            serverApplicationAgentTypeComboBox.setSelectedItem(nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_application.type);

        }
        else{
            serviceNameTextField.setText("Service"+nsdhController.nsdhModel.sequences.serviceSequence);
        }

        //pobierz parametry do tabel
        createClientParamsTableFields((String)clientAgentTypeComboBox.getSelectedItem());
        createServerTransportParamsTableFields((String)serverTransportAgentTypeComboBox.getSelectedItem());
        createServerApplicationParamsTableFields((String)serverApplicationAgentTypeComboBox.getSelectedItem());

    }

    private void createClientParamsTableFields(String selectedAgentType){

            String[] values = new String[]{"Nazwa", "Wartosc"};
            clientParamsTable.setModel(new DefaultTableModel(values,0) {
                                     @Override
                                     //tylko 2-ga kolumna moze byc edytowana
                                     public boolean isCellEditable(int row, int column)
                                     {
                                         if (column==0)
                                             return false;
                                         else
                                             return true;
                                     }
                                 }
                    );
            DefaultTableModel model = (DefaultTableModel)clientParamsTable.getModel();

            //sprawdz czy jest to edycja i czy istnieje taka usluga
            Boolean loadParamsFromNsdhModel = false;
            String loadedAgentType = "";
            if(serviceName!=null && !serviceName.equals("") && nsdhController.nsdhModel.network_settings.service_list.containsKey(serviceName)){
                loadParamsFromNsdhModel = true;
                
                loadedAgentType = nsdhController.nsdhModel.network_settings.service_list.get(serviceName).client_sink.client_agent;
            }

            String[] rowArray = new String[2];
            rowArray[0]="prio";
            rowArray[1]="";
            if(loadParamsFromNsdhModel){
                 rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).client_sink.client_agent_params.prio;
            }
            model.insertRow(model.getRowCount(),rowArray);

            rowArray = new String[2];
            rowArray[0]="flags";
            rowArray[1]="";
            if(loadParamsFromNsdhModel){
                 rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).client_sink.client_agent_params.flags;
            }
            model.insertRow(model.getRowCount(),rowArray);


            rowArray = new String[2];
            rowArray[0]="ttl";
            rowArray[1]="";
            if(loadParamsFromNsdhModel){
                 rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).client_sink.client_agent_params.ttl;
            }
            model.insertRow(model.getRowCount(),rowArray);


            //parametry dla agentow zaczynajacych sie na Agent/TCPSink
            if(selectedAgentType.startsWith("Agent/TCPSink")){

                rowArray = new String[2];
                rowArray[0]="packetSize";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedAgentType.startsWith("Agent/TCPSink")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).client_sink.client_agent_params.client_agent_TCPSink_params.packetSize;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="maxSackBlocks";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedAgentType.startsWith("Agent/TCPSink")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).client_sink.client_agent_params.client_agent_TCPSink_params.maxSackBlocks;
                }
                model.insertRow(model.getRowCount(),rowArray);
                
            }


            //parametry dla agentow zaczynajacych sie na Agent/TCPSink/DelAck
            if(selectedAgentType.startsWith("Agent/TCPSink/DelAck")){

                rowArray = new String[2];
                rowArray[0]="interval";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedAgentType.startsWith("Agent/TCPSink/DelAck")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).client_sink.client_agent_params.client_agent_TCPSink_params.client_agent_TCPSink_DelAck_params.interval;
                }
                model.insertRow(model.getRowCount(),rowArray);

            }

            //parametry dla agentow zaczynajacych sie na Agent/TCPSink/Sack1/DelAck
            if(selectedAgentType.startsWith("Agent/TCPSink/Sack1/DelAck")){

                rowArray = new String[2];
                rowArray[0]="interval";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedAgentType.startsWith("Agent/TCPSink/Sack1/DelAck")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).client_sink.client_agent_params.client_agent_TCPSink_params.client_agent_TCPSink_Sack1_DelAck_params.interval;
                }
                model.insertRow(model.getRowCount(),rowArray);

            }

    }


    private void createServerTransportParamsTableFields(String selectedAgentType){

        //inicjalizuj model tabeli
        String[] values = new String[]{"Nazwa", "Wartosc"};
        serverTransportParamsTable.setModel(new DefaultTableModel(values,0) {
                                 @Override
                                 //tylko 2-ga kolumna moze byc edytowana
                                 public boolean isCellEditable(int row, int column)
                                 {
                                     if (column==0)
                                         return false;
                                     else
                                         return true;
                                 }
                             }
                );
        DefaultTableModel model = (DefaultTableModel)serverTransportParamsTable.getModel();

        
        //sprawdz czy jest to edycja i czy istnieje taka usluga
        Boolean loadParamsFromNsdhModel = false;
        String loadedAgentType = "";
        if(serviceName!=null && !serviceName.equals("") && nsdhController.nsdhModel.network_settings.service_list.containsKey(serviceName)){
            loadParamsFromNsdhModel = true;

            loadedAgentType = nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_transport.server_agent;
        }

        String[] rowArray = new String[2];
        rowArray[0]="prio";
        rowArray[1]="";
        if(loadParamsFromNsdhModel){
             rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_transport.server_agent_params.prio;
        }
        model.insertRow(model.getRowCount(),rowArray);


        rowArray = new String[2];
        rowArray[0]="flags";
        rowArray[1]="";
        if(loadParamsFromNsdhModel){
             rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_transport.server_agent_params.flags;
        }
        model.insertRow(model.getRowCount(),rowArray);


        rowArray = new String[2];
        rowArray[0]="ttl";
        rowArray[1]="";
        if(loadParamsFromNsdhModel){
             rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_transport.server_agent_params.ttl;
        }
        model.insertRow(model.getRowCount(),rowArray);


        //wczytaj parametry Agent/TCP
        if(selectedAgentType.startsWith("Agent/TCP")){

                rowArray = new String[2];
                rowArray[0]="window";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedAgentType.startsWith("Agent/TCP")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_transport.server_agent_params.server_agent_TCP_params.window;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="windowInit";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedAgentType.startsWith("Agent/TCP")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_transport.server_agent_params.server_agent_TCP_params.windowInit;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="windowOption";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedAgentType.startsWith("Agent/TCP")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_transport.server_agent_params.server_agent_TCP_params.windowOption;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="windowConstant";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedAgentType.startsWith("Agent/TCP")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_transport.server_agent_params.server_agent_TCP_params.windowConstant;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="windowThresh";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedAgentType.startsWith("Agent/TCP")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_transport.server_agent_params.server_agent_TCP_params.windowThresh;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="overhead";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedAgentType.startsWith("Agent/TCP")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_transport.server_agent_params.server_agent_TCP_params.overhead;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="ecn";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedAgentType.startsWith("Agent/TCP")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_transport.server_agent_params.server_agent_TCP_params.ecn;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="packetSize";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedAgentType.startsWith("Agent/TCP")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_transport.server_agent_params.server_agent_TCP_params.packetSize;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="bugFix";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedAgentType.startsWith("Agent/TCP")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_transport.server_agent_params.server_agent_TCP_params.bugFix;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="slow_start_restart";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedAgentType.startsWith("Agent/TCP")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_transport.server_agent_params.server_agent_TCP_params.slow_start_restart;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="tcpTick";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedAgentType.startsWith("Agent/TCP")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_transport.server_agent_params.server_agent_TCP_params.tcpTick;
                }
                model.insertRow(model.getRowCount(),rowArray);

                //wczytaj parametry Agent/TCP/NewReno
                if(selectedAgentType.startsWith("Agent/TCP/NewReno")){

                    rowArray = new String[2];
                    rowArray[0]="newreno_changes";
                    rowArray[1]="";
                    if(loadParamsFromNsdhModel && loadedAgentType.startsWith("Agent/TCP/NewReno")){
                        rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_transport.server_agent_params.server_agent_TCP_params.server_agent_TCP_NewReno_params.newreno_changes;
                    }
                    model.insertRow(model.getRowCount(),rowArray);
                }
                
        }


        //wczytaj parametry Agent/UDP
        if(selectedAgentType.startsWith("Agent/UDP")){

                rowArray = new String[2];
                rowArray[0]="packetSize";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedAgentType.startsWith("Agent/UDP")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_transport.server_agent_params.server_agent_UDP_params.packetSize;
                }
                model.insertRow(model.getRowCount(),rowArray);
        }

    }


    private void createServerApplicationParamsTableFields(String selectedApplicationType){

        //inicjalizuj model tabeli
        String[] values = new String[]{"Nazwa", "Wartosc"};
        serverApplicationParamsTable.setModel(new DefaultTableModel(values,0) {
                                 @Override
                                 //tylko 2-ga kolumna moze byc edytowana
                                 public boolean isCellEditable(int row, int column)
                                 {
                                     if (column==0)
                                         return false;
                                     else
                                         return true;
                                 }
                             }
                );
        DefaultTableModel model = (DefaultTableModel)serverApplicationParamsTable.getModel();


        //sprawdz czy jest to edycja i czy istnieje taka usluga
        Boolean loadParamsFromNsdhModel = false;
        String loadedApplicationType = "";
        if(serviceName!=null && !serviceName.equals("") && nsdhController.nsdhModel.network_settings.service_list.containsKey(serviceName)){
            loadParamsFromNsdhModel = true;

            loadedApplicationType = nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_application.type;
        }

        
        String[] rowArray; //tymczasowa zmienna przechowujaca wartosc wiersza ladowanego


        //wczytaj parametry w zaleznosci od wybranego typu aplikacji

         if(selectedApplicationType.equals("Application/Traffic/Exponential")){

                rowArray = new String[2];
                rowArray[0]="packetSize";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedApplicationType.equals("Application/Traffic/Exponential")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_application.application_Traffic_Exponential_params.packetSize;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="burst_time";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedApplicationType.equals("Application/Traffic/Exponential")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_application.application_Traffic_Exponential_params.burst_time;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="idle_time";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedApplicationType.equals("Application/Traffic/Exponential")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_application.application_Traffic_Exponential_params.idle_time;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="rate";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedApplicationType.equals("Application/Traffic/Exponential")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_application.application_Traffic_Exponential_params.rate;
                }
                model.insertRow(model.getRowCount(),rowArray);
        }


        else if(selectedApplicationType.equals("Application/Traffic/Pareto")){

                rowArray = new String[2];
                rowArray[0]="packetSize";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedApplicationType.equals("Application/Traffic/Pareto")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_application.application_Traffic_Pareto_params.packetSize;
                }
                model.insertRow(model.getRowCount(),rowArray);


                rowArray = new String[2];
                rowArray[0]="burst_time";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedApplicationType.equals("Application/Traffic/Pareto")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_application.application_Traffic_Pareto_params.burst_time;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="idle_time";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedApplicationType.equals("Application/Traffic/Pareto")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_application.application_Traffic_Pareto_params.idle_time;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="rate";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedApplicationType.equals("Application/Traffic/Pareto")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_application.application_Traffic_Pareto_params.rate;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="shape";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedApplicationType.equals("Application/Traffic/Pareto")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_application.application_Traffic_Pareto_params.shape;
                }
                model.insertRow(model.getRowCount(),rowArray);
        }


        else if(selectedApplicationType.equals("Application/Traffic/CBR")){

                rowArray = new String[2];
                rowArray[0]="rate";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedApplicationType.equals("Application/Traffic/CBR")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_application.application_Traffic_CBR_params.rate;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="interval";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedApplicationType.equals("Application/Traffic/CBR")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_application.application_Traffic_CBR_params.interval;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="packetSize";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedApplicationType.equals("Application/Traffic/CBR")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_application.application_Traffic_CBR_params.packetSize;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="random";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedApplicationType.equals("Application/Traffic/CBR")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_application.application_Traffic_CBR_params.random;
                }
                model.insertRow(model.getRowCount(),rowArray);

                rowArray = new String[2];
                rowArray[0]="maxpkts";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedApplicationType.equals("Application/Traffic/CBR")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_application.application_Traffic_CBR_params.maxpkts;
                }
                model.insertRow(model.getRowCount(),rowArray);
        }


        else if(selectedApplicationType.equals("Application/Telnet")){

                rowArray = new String[2];
                rowArray[0]="interval";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedApplicationType.equals("Application/Telnet")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_application.application_Telnet_params.interval;
                }
                model.insertRow(model.getRowCount(),rowArray);
        }



        else  if(selectedApplicationType.equals("Application/FTP")){

                rowArray = new String[2];
                rowArray[0]="maxpkts";
                rowArray[1]="";
                if(loadParamsFromNsdhModel && loadedApplicationType.equals("Application/FTP")){
                    rowArray[1]=nsdhController.nsdhModel.network_settings.service_list.get(serviceName).server_application.application_FTP_params.maxpkts;
                }
                model.insertRow(model.getRowCount(),rowArray);
        }


    }


    /**
     * Zapisuje stan okna do modelu nsdh
     * @throws Exception
     */
    private void saveServiceToNsdhModel() throws Exception{

        //zakoncz edycje w tabelach, jesli jakies komorki sa edytowane
        
        if(clientParamsTable.getCellEditor()!=null){
                clientParamsTable.getCellEditor().stopCellEditing();
        }
        if(serverTransportParamsTable.getCellEditor()!=null){
                serverTransportParamsTable.getCellEditor().stopCellEditing();
        }
        if(serverApplicationParamsTable.getCellEditor()!=null){
                serverApplicationParamsTable.getCellEditor().stopCellEditing();
        }

        //obiekt tymczasowy
        Service tempService = new Service();

        //ustaw nazwe uslugi
        if((serviceName==null || serviceName.equals("")) && nsdhController.nsdhModel.network_settings.service_list.containsKey(serviceNameTextField.getText())){
            throw new Exception("Usluga o podanej nazwie juz istnieje, zmien nazwe");
        }
        if(serviceNameTextField.getText().equals("")){
            throw new Exception("Nazwa nie moze byc pusta.");
        }
        tempService.name = serviceNameTextField.getText();


        //------------------zapisanie danych z tabeli klient----------------------------
        DefaultTableModel clientParamsTableModel = (DefaultTableModel)clientParamsTable.getModel();

        //wybrany typ agenta
        tempService.client_sink.client_agent=(String)clientAgentTypeComboBox.getSelectedItem();

        //parametry dla wsz typow agentow
        tempService.client_sink.client_agent_params.prio=(String)clientParamsTableModel.getValueAt(0, 1);
        tempService.client_sink.client_agent_params.flags=(String)clientParamsTableModel.getValueAt(1, 1);
        tempService.client_sink.client_agent_params.ttl=(String)clientParamsTableModel.getValueAt(2, 1);

        //parametry dla agentow zaczynajacych sie na Agent/TCPSink
        if(tempService.client_sink.client_agent.startsWith("Agent/TCPSink")){
            tempService.client_sink.client_agent_params.client_agent_TCPSink_params.packetSize=(String)clientParamsTableModel.getValueAt(3, 1);
            tempService.client_sink.client_agent_params.client_agent_TCPSink_params.maxSackBlocks=(String)clientParamsTableModel.getValueAt(4, 1);
        }

        //parametry dla agentow zaczynajacych sie na Agent/TCPSink/DelAck
        if(tempService.client_sink.client_agent.startsWith("Agent/TCPSink/DelAck")){
            tempService.client_sink.client_agent_params.client_agent_TCPSink_params.client_agent_TCPSink_DelAck_params.interval = (String)clientParamsTableModel.getValueAt(5, 1);
        }//parametry dla agentow zaczynajacych sie na Agent/TCPSink/Sack1/DelAck
        else if(tempService.client_sink.client_agent.startsWith("Agent/TCPSink/Sack1/DelAck")){
            tempService.client_sink.client_agent_params.client_agent_TCPSink_params.client_agent_TCPSink_Sack1_DelAck_params.interval = (String)clientParamsTableModel.getValueAt(5, 1);
        }


        //------------------zapisanie danych z tabeli server transport----------------------------

        DefaultTableModel serverTransportParamsTableModel = (DefaultTableModel)serverTransportParamsTable.getModel();

        //wybrany typ agenta
        tempService.server_transport.server_agent=(String)serverTransportAgentTypeComboBox.getSelectedItem();

        //parametry dla wsz typow agentow
        tempService.server_transport.server_agent_params.prio=(String)serverTransportParamsTableModel.getValueAt(0, 1);
        tempService.server_transport.server_agent_params.flags=(String)serverTransportParamsTableModel.getValueAt(1, 1);
        tempService.server_transport.server_agent_params.ttl=(String)serverTransportParamsTableModel.getValueAt(2, 1);
        
        //wczytaj parametry Agent/TCP
        if(tempService.server_transport.server_agent.startsWith("Agent/TCP")){
            tempService.server_transport.server_agent_params.server_agent_TCP_params.window = (String)serverTransportParamsTableModel.getValueAt(3, 1);
            tempService.server_transport.server_agent_params.server_agent_TCP_params.windowInit = (String)serverTransportParamsTableModel.getValueAt(4, 1);
            tempService.server_transport.server_agent_params.server_agent_TCP_params.windowOption = (String)serverTransportParamsTableModel.getValueAt(5, 1);
            tempService.server_transport.server_agent_params.server_agent_TCP_params.windowConstant = (String)serverTransportParamsTableModel.getValueAt(6, 1);
            tempService.server_transport.server_agent_params.server_agent_TCP_params.windowThresh = (String)serverTransportParamsTableModel.getValueAt(7, 1);
            tempService.server_transport.server_agent_params.server_agent_TCP_params.overhead = (String)serverTransportParamsTableModel.getValueAt(8, 1);
            tempService.server_transport.server_agent_params.server_agent_TCP_params.ecn = (String)serverTransportParamsTableModel.getValueAt(9, 1);
            tempService.server_transport.server_agent_params.server_agent_TCP_params.packetSize = (String)serverTransportParamsTableModel.getValueAt(10, 1);
            tempService.server_transport.server_agent_params.server_agent_TCP_params.bugFix = (String)serverTransportParamsTableModel.getValueAt(11, 1);
            tempService.server_transport.server_agent_params.server_agent_TCP_params.slow_start_restart = (String)serverTransportParamsTableModel.getValueAt(12, 1);
            tempService.server_transport.server_agent_params.server_agent_TCP_params.tcpTick = (String)serverTransportParamsTableModel.getValueAt(13, 1);

            //wczytaj parametry Agent/TCP/NewReno
            if(tempService.server_transport.server_agent.startsWith("Agent/TCP/NewReno")){
                tempService.server_transport.server_agent_params.server_agent_TCP_params.server_agent_TCP_NewReno_params.newreno_changes = (String)serverTransportParamsTableModel.getValueAt(14, 1);
            }

        }

        //wczytaj parametry Agent/UDP
        if(tempService.server_transport.server_agent.startsWith("Agent/UDP")){
            tempService.server_transport.server_agent_params.server_agent_UDP_params.packetSize = (String)serverTransportParamsTableModel.getValueAt(3, 1);
        }
        
        
        //------------------zapisanie danych z tabeli server application----------------------------

        DefaultTableModel serverApplicationParamsTableModel = (DefaultTableModel)serverApplicationParamsTable.getModel();

        //wybrany typ agenta
        tempService.server_application.type=(String)serverApplicationAgentTypeComboBox.getSelectedItem();

        //wczytaj parametry Application/Traffic/Exponential
        if(tempService.server_application.type.equals("Application/Traffic/Exponential")){
            tempService.server_application.application_Traffic_Exponential_params.packetSize = (String)serverApplicationParamsTableModel.getValueAt(0, 1);
            tempService.server_application.application_Traffic_Exponential_params.burst_time = (String)serverApplicationParamsTableModel.getValueAt(1, 1);
            tempService.server_application.application_Traffic_Exponential_params.idle_time = (String)serverApplicationParamsTableModel.getValueAt(2, 1);
            tempService.server_application.application_Traffic_Exponential_params.rate = (String)serverApplicationParamsTableModel.getValueAt(3, 1);
        }
        //wczytaj parametry Application/Traffic/Pareto
        else if(tempService.server_application.type.equals("Application/Traffic/Pareto")){
            tempService.server_application.application_Traffic_Pareto_params.packetSize = (String)serverApplicationParamsTableModel.getValueAt(0, 1);
            tempService.server_application.application_Traffic_Pareto_params.burst_time = (String)serverApplicationParamsTableModel.getValueAt(1, 1);
            tempService.server_application.application_Traffic_Pareto_params.idle_time = (String)serverApplicationParamsTableModel.getValueAt(2, 1);
            tempService.server_application.application_Traffic_Pareto_params.rate = (String)serverApplicationParamsTableModel.getValueAt(3, 1);
            tempService.server_application.application_Traffic_Pareto_params.shape = (String)serverApplicationParamsTableModel.getValueAt(4, 1);
        }
        //wczytaj parametry Application/Traffic/CBR
        else if(tempService.server_application.type.equals("Application/Traffic/CBR")){
            tempService.server_application.application_Traffic_CBR_params.rate = (String)serverApplicationParamsTableModel.getValueAt(0, 1);
            tempService.server_application.application_Traffic_CBR_params.interval = (String)serverApplicationParamsTableModel.getValueAt(1, 1);
            tempService.server_application.application_Traffic_CBR_params.packetSize = (String)serverApplicationParamsTableModel.getValueAt(2, 1);
            tempService.server_application.application_Traffic_CBR_params.random = (String)serverApplicationParamsTableModel.getValueAt(3, 1);
            tempService.server_application.application_Traffic_CBR_params.maxpkts = (String)serverApplicationParamsTableModel.getValueAt(4, 1);
        }
        //wczytaj parametry Application/Telnet
        else if(tempService.server_application.type.equals("Application/Telnet")){
            tempService.server_application.application_Telnet_params.interval = (String)serverApplicationParamsTableModel.getValueAt(0, 1);
        }
        //wczytaj parametry Application/Telnet
        else if(tempService.server_application.type.equals("Application/FTP")){
            tempService.server_application.application_FTP_params.maxpkts = (String)serverApplicationParamsTableModel.getValueAt(0, 1);
        }


        //dodaj usluge do listy jesli nazwa to null
        if(serviceName==null || serviceName.equals("")){
            nsdhController.nsdhModel.network_settings.service_list.put(tempService.name, tempService);
            nsdhController.nsdhModel.sequences.serviceSequence++;
        }
        else{
            //edycja - zamien nazwe w innych obiektach korzystajacych z uslugi (polaczeniach,kolejkach) i podmien
            nsdhController.RenameService(serviceName, tempService.name);
            nsdhController.nsdhModel.network_settings.service_list.put(tempService.name, tempService);
        }
        

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JComboBox clientAgentTypeComboBox;
    private javax.swing.JLabel clientAgentTypeLabel;
    private javax.swing.JPanel clientPanel;
    private javax.swing.JLabel clientParamsLabel;
    private javax.swing.JScrollPane clientParamsScrollPane;
    private javax.swing.JTable clientParamsTable;
    private javax.swing.JButton okButton;
    private javax.swing.JComboBox serverApplicationAgentTypeComboBox;
    private javax.swing.JLabel serverApplicationAgentTypeLabel;
    private javax.swing.JPanel serverApplicationPanel;
    private javax.swing.JLabel serverApplicationParamsLabel;
    private javax.swing.JScrollPane serverApplicationParamsScrollPane;
    private javax.swing.JTable serverApplicationParamsTable;
    private javax.swing.JPanel serverPanel;
    private javax.swing.JComboBox serverTransportAgentTypeComboBox;
    private javax.swing.JLabel serverTransportAgentTypeLabel;
    private javax.swing.JPanel serverTransportPanel;
    private javax.swing.JLabel serverTransportParamsLabel;
    private javax.swing.JScrollPane serverTransportParamsScrollPane;
    private javax.swing.JTable serverTransportParamsTable;
    private javax.swing.JLabel serviceNameLabel;
    private javax.swing.JTextField serviceNameTextField;
    // End of variables declaration//GEN-END:variables

    private NsdhController nsdhController;
    private GraphPanel graphPanel;
    private String serviceName;
    private NetworkSettingsFrame networkSettingsFrame;

}
